<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>购买商品</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <input type="hidden" name="oId" placeholder="" th:value="${order.id}" class="layui-input">

                <div class="layui-form-item">
                    <label class="layui-form-label">菜品名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" disabled  th:value="${order.fName}" autocomplete="off" placeholder="菜品名" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline">
                        <img th:src="${order.fImg}" disabled="" width="310px" height="210px">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">种类</label>
                    <div class="layui-input-inline">
                        <input type="text" disabled  th:value="${order.kName}" autocomplete="off"  class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">单价</label>
                    <div class="layui-input-inline">
                        <input type="number" disabled  name="price" th:value="${order.fPrice}" autocomplete="off" placeholder="单价" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">数量</label>
                    <div class="layui-input-inline">
                        <input type="number" disabled th:value="${order.nums}"  autocomplete="off" placeholder="数量" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">总价</label>
                    <div class="layui-input-inline">
                        <input type="number" disabled  name="price" th:value="${order.fPrice}*${order.nums}" autocomplete="off" placeholder="总价" class="layui-input">
                    </div>
                </div>




            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="order-buy">
                <i class="layui-icon layui-icon-ok"></i>
                购买
            </button>

        </div>
    </div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
    layui.use(['form','jquery'],function(){
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit(order-buy)', function(data){
            $.ajax({
                type: 'post', // 提交方式 get/post
                url: '/order/buyOrder', // 需要提交的 url
                data: {
                    oId: $('input[name=oId]').val()
                },
                dataType:'json',
                success: function(result) {
                    console.log(result);
                    if (parseInt(result.code) === 200) {
                        layer.msg(result.message, {
                            icon: 1,
                            time: 1000,
                            area:['120px','100px']
                        },function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        });
                    } else {
                        layer.msg(result.message, {
                            icon: 2,
                            time: 1000,
                            area:['120px','180px']
                        },function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                        });
                    }
                },
                error:function (result) {
                    console.log(result);
                    layer.msg("购买失败,请稍后再试", {
                        icon: 2,
                        time: 1000,
                        area:['120px','180px']
                    },function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                    });
                }
            });
            return false; // 阻止表单自动提交事件，必须返回false，否则表单会自己再做一次提交操作，并且页面跳转

        });
    });


</script>

</body>
</html>